<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="<c:url value='/static/themes/css/bootstrap-datetimepicker.min.css'/>" rel="stylesheet" media="screen">

<script src="<c:url value='/static/jquery/jquery-1.9.1.min.js'/>" type="text/javascript"></script>
<script type="text/javascript" src="<c:url value='/static/themes/js/jquery.datatables.min.js'/>"></script>
<link href="<c:url value='/static/themes/dataTables/select.dataTables.min.css'/>"
	rel="stylesheet" media="screen">
<script src="<c:url value='/static/themes/dataTables/dataTables.buttons.min.js'/>"></script>
<script src="<c:url value='/static/themes/dataTables/dataTables.select.min.js'/>"></script>	
<script type="text/javascript" src="<c:url value='/static/datetimepicker/js/bootstrap-datetimepicker.js'/>"charset="UTF-8"></script>	
<title>商家充值管理页面</title>
</head>
<body>
	<div class="panel panel-default bk-bg-white">
		<div class="panel-body">
		<form class="form-horizontal" id="searchForm" method="post" action="#">
			<div class="row">
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">商家生财ID：</label> 
					<div class="col-sm-8">
						<input type="text" class="form-control" name="businessUserID" id="businessUserID"  placeholder="商家生财ID">
					</div>
				</div>
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">充值金额：</label> 
					<div class="col-sm-8">
						<input type="text" class="form-control" name="minRechargeAmount" id="minRechargeAmount"  placeholder="充值金额最小值">
						
					</div>
				</div>
				<div class="form-group col-sm-4">
					<label  class="col-sm-1 control-label">-</label>
					<div class="col-sm-8">
   						<input type="text" class="form-control" name="maxRechargeAmount" id="maxRechargeAmount"  placeholder="充值金额最大值">
					</div>
				</div>
			</div>
			<div class="row">
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">充值状态：</label> 
					<div class="col-sm-8">
						<select id="statusInfor" name="statusInfor" class="form-control">
							<option value="">全部状态</option>
							<option selected="selected" value="1">待处理</option>
							<option value="2">已充值</option>
							<option value="3">已驳回</option>
						</select>
					</div>
				</div>
				<div class="form-group col-sm-4">
					<label  class="col-sm-4 control-label">申请时间：</label> 
					<div class="col-sm-8">
   						<input class="input-append date form_datetime form-control" name="startApplicationRechargeTime" id="startApplicationRechargeTime" >
						    <span class="add-on"><i class="icon-remove"></i></span>
						    <span class="add-on"><i class="icon-calendar"></i></span>
					</div>
				</div>
				<div class="form-group col-sm-4">
					<label  class="col-sm-1 control-label">-</label>
					<div class="col-sm-8">
   						<input class="input-append date form_datetime form-control" name="endApplicationRechargeTime" id="endApplicationRechargeTime" >
						    <span class="add-on"><i class="icon-remove"></i></span>
						    <span class="add-on"><i class="icon-calendar"></i></span>
					</div>
				</div>
			</div>
			<div class="form-group col-sm-12" style="padding-bottom: 15px; text-align: center;">
					<button id="search" type="button" class="btn btn-primary glyphicon glyphicon-search"> 搜索</button>
					<button id="report" type="button" class="btn btn-success glyphicon glyphicon-download"> 批量导出</button>
			</div>
		</form>	
		</div>
	</div>
	<!-- panel-body -->
	<div id="message"></div>
	<!-- panel -->
	<div class="panel panel-default">
		<div class="panel-body">
			<div class="table-responsive">
				<div id="table1_wrapper" class="dataTables_wrapper no-footer">
					<div class="form-group col-sm-5">
						<div class="col-sm-4">
							<select id="control_statusInfor" class="form-control ">
								<option value="2">通过</option>
								<option value="3">驳回</option>
							</select>
						</div>
						<button class="btn btn-warning " id="sure">确定</button>
					</div>
					<table id="table" class="display nowrap" cellspacing="0" width="100%">
						<thead>
							<tr role="row">
								<th><input type="checkbox" class="checkall" />全选</th>
								<th>商家生财ID</th>
								<th>充值申请时间</th>
								<th>充值金额</th>
								<th>转账银行</th>
								<th>转账人姓名</th>
								<th>充值银行账号</th>
								<th>充值状态</th>
								<th>处理时间</th>
								<th>操作</th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
		</div>
		<div id="page">
			
		</div>
	</div>

	<script type="text/javascript">
	
	
	$(function($) {
		//日期控件
		$('#startApplicationRechargeTime').datetimepicker({
			language : 'zh-CN',
			format : 'yyyy-mm-dd hh:ii', 
			autoclose : true,
			todayBtn : true,
			minuteStep : 10
		}).on('changeDate', function (ev) {
			var starttime = $(this).val();
			$('#endApplicationRechargeTime').datetimepicker('setStartDate',starttime);
            $(this).datetimepicker('hide');  
        });
		
		$('#endApplicationRechargeTime').datetimepicker({
			language : 'zh-CN',
			format : 'yyyy-mm-dd hh:ii',
			autoclose : true,
			todayBtn : true,
			minuteStep : 10
		}).on('changeDate', function (ev) {
			var time = $(this).val();
			$('#startApplicationRechargeTime').datetimepicker('setEndDate',time);
            $(this).datetimepicker('hide');  
        });
		function doSearch(){
			var table=$('#table').DataTable({
		        "processing": true,
		        "serverSide": true,
		        "bLengthChange": false,
		        "bFilter": false,
		        "bSort":false,
		        "bDestroy":true,
		        "bAutoWidth": false,
		        "sScrollX": "100%",
		        "sScrollY": "100%",
		        "language": {
		            "url": path+"/static/language_datatables.json"
		        },
		        "ajax": {
		            "url": path+"/capital/getRechargeDetailList",
		            "type": "POST",
		            "data":{
			                    "businessUserID": $('#businessUserID').val(),
			                    "statusInfor": $('#statusInfor').val(),
			                    "minRechargeAmount": $('#minRechargeAmount').val(),
			                    "maxRechargeAmount": $('#maxRechargeAmount').val(),
			                    "endApplicationRechargeTime": $('#endApplicationRechargeTime').val(),
			                    "startApplicationRechargeTime": $('#startApplicationRechargeTime').val()
			            	}
		        },
		        "oSearch":{
		        	
		        },
		        select: {
		            style:    'os',
		            selector: 'td:first-child'
		        },
		        "columns": [
					{ "data": "businessuserid" ,"width": "5%"},
		            { "data": "businessuserid" ,"width": "10%"},
		            { "data": "applicationrechargetime" ,"width": "10%"},
		            { "data": "rechargeamount","width": "10%" },
		            { "data": "bankname" ,"width": "10%"},
		            { "data": "payername" ,"width": "10%"},
		            { "data": "bankcardaccount" ,"width": "10%"},
		            { "data": "statusinfor" ,"width": "10%"},
		            { "data": "completiontime","width": "10%"},
		            { "data": "businessuserid","width": "20%"}
		        ],
		        "columnDefs": [
                      {
   	                     "render": function ( data, type, row ) {
   	                    	if(row.statusinfor==1){
	   	                    	 return '<input type="checkbox"  class="checkchild"  value="' + data + '_'+row.applicationrechargetime+'"/>';
   	                    	}
   	                    	return "";
   	                     },
   	                     "targets": 0
   	                 },
	                 {
	                     "render": function ( data, type, row ) {
	                    	 return dateTimeFormatter(data);
	                     },
	                     "targets": 2
	                 },
	                 {
	                     "render": function ( data, type, row ) {
	                    	 return dateTimeFormatter(data);
	                     },
	                     "targets": 8
	                 },
	                 {
	                     "render": function ( data, type, row ) {
	                    	 if(data=="1"){
	                    		 return "待处理";
	                    	 }else  if(data=="2"){
	                    		 return "已充值";
	                    	 }else  if(data=="3"){
	                    		 return "已驳回";
	                    	 }else{return "";}
	                     },
	                     "targets": 7
	                 },
	                 {
	                     "render": function ( data, type, row ) {
		                    	if(row.statusinfor==1){
		                    		var ret= '<button class="btn btn-warning recharge" key="'+data+'" statusInfor="2" time="'+row.applicationrechargetime+' ">通过</button>&nbsp;'
			                       	ret +='<button class="btn btn-warning recharge" key="'+data+'" statusInfor="3" time="'+row.applicationrechargetime+'">驳回</button>&nbsp;';
			                     	return ret;
		                    	}
		                     	return "";
	                     },
	                     "targets": 9
	                 }
	             ]

		    });
			
		};
		doSearch();
		bindCheck();
		bandclick();
		//查询事件
		$('#search').click(function(){
			doSearch();
		});
		
		$(".checkall").click(function () {
		      var check = $(this).prop("checked");
		      $(".checkchild").prop("checked", check);
		});
		function bindCheck(){
			$("body").on("click",".checkchild",function(){
				var child=$(".checkchild");
				var ifCheckAll=true;
				for(var i=0;i<child.length;i++){
					var check=$(child[i]).prop("checked");
					if(!check){
						ifCheckAll=false;
						$(".checkall").prop("checked","false");
						break;
					}
				}
				$(".checkall").prop("checked",ifCheckAll);
			});
			
			
		};
		$("#sure").on("click",function(){
			var child=$(".checkchild:checked");
			if(child.length==0){
				alert("请选择需要操作的信息");
				return false;
			}
			var businessUserID="";
			var applicationRechargeTime="";
			child.each(function(i,o){
				var value=o.value.toString().split("_");
				businessUserID+=value[0];
				applicationRechargeTime+=value[1];
				if(i!=child.length-1){
					applicationRechargeTime+=",";
					businessUserID+=",";
				}
			});
			var statusInfor=$("#control_statusInfor").val();
			updateRechargeDetails(businessUserID,applicationRechargeTime,statusInfor);
			
		});
		function bandclick(){
			$('body').on("click",'.recharge',function(){
				_t = $(this);
				var businessUserID=_t.attr('key');
				var applicationRechargeTime=_t.attr('time');
				var statusInfor=_t.attr('statusInfor');
				updateRechargeDetails(businessUserID,applicationRechargeTime,statusInfor);
			});
		}
		
		
		function updateRechargeDetails(businessUserID,applicationRechargeTime,statusInfor){
			
			$.ajax({
				type : "post",
				url : path  + "/capital/updateRechargeDetails",
				cache : false,
				data : {
					businessUserID : businessUserID,
					applicationRechargeTime : applicationRechargeTime,
					statusInfor:statusInfor,
					_t : new Date().getTime()
				},
				dataType : "json",
				success : function(data) {
					showmessage(data.msg);
					if (data.success) {
						doSearch();
					}
				}
		});
	}
		
	});
	//导出
	$('#report').click(function(){
		$('#searchForm').attr("action",path+"/capital/reportRechargeDetail");
		$('#searchForm').submit();
		$('#searchForm').attr("action","");
	});
	
	
	//显示消息
	function showmessage(msg,callback){
		$('#message').ucMessage({
			msg:msg,
			callback:callback
		});
	}
	 
	</script>
</body>
</html>